package com.dragon.backstage.controller;

import com.dragon.backstage.domain.param.login.LoginParam;
import com.dragon.backstage.domain.vo.login.LoginVo;
import com.dragon.backstage.service.LoginService;
import com.dragon.common.utils.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 登陆控制器
 *
 * @author dragon
 * @version 1.0
 * @date 2024/8/1 17:32
 */
@RestController
@RequestMapping("/api")
@Tag(name = "登陆模块接口")
public class LoginController {

    @Resource
    private LoginService loginService;


    /**
     * 图片验证码
     *
     * @throws IOException IO异常
     */
    @GetMapping("/captcha")
    @Operation(summary = "图片验证码")
    public void captcha() throws IOException {
        loginService.captcha();
    }

    /**
     * 登陆
     *
     * @param param 登陆参数
     * @return 登陆信息
     */
    @PostMapping("/login")
    @Operation(summary = "登陆")
    public AjaxResult<LoginVo> login(@Valid @RequestBody LoginParam param) {
        return loginService.login(param);
    }

    /**
     * 注销
     *
     * @return 注销结果
     */
    @GetMapping("/logout")
    @Operation(summary = "注销")
    public AjaxResult<Void> logout() {
        return loginService.logout();
    }

}
